<template>
    <view class="container">
        <view class=" bg-white p-30">
            <u-section title="常用功能" :right="false"></u-section>
            <view class="flex m-t-20">
                <view class="flex flex-col col-center" @click="handleScan('add')">
                    <u-icon name="scan" size="50"></u-icon>
                    <span class="m-t-10">扫码入库(仓库)</span>
                </view>
                <view class="flex flex-col col-center u-m-l-40" @click="handleScan('select')">
                    <u-icon name="scan" size="50"></u-icon>
                    <span class="m-t-10">扫码查看</span>
                </view>
            </view>
        </view>

        <view class=" bg-white p-30 m-t-30">
            <u-section title="全部功能" :right="false"></u-section>
            <view class=" m-t-20">
                <u-grid :col="3">
                    <block v-for="item in gradList" :key="item.name">
                        <u-grid-item @click="goToPage(item.name)">
                            <u-icon :name="item.name" :size="46"></u-icon>
                            <view class="grid-text m-t-10">{{item.text}}</view>
                        </u-grid-item>
                    </block>
                </u-grid>
            </view>
        </view>
    </view>
</template>

<script setup>
    import {
        ref
    } from 'vue'
    import {
        onLoad
    } from '@dcloudio/uni-app'
    import {
        apiGetHomepageInfo
    } from '@/api/index.js'
    import {
        IMG_BASE_URL
    } from '@/utils/appConfig.js'

    const token = ref('')
    //相应页面根据name的名称来命名
    const gradList = ref([{
        name: 'file-text',
        text: '采购'
    }, {
        name: 'home',
        text: '仓库'
    }, {
        name: 'setting',
        text: '养护'
    }, {
        name: 'rmb',
        text: '销售'
    }, {
        name: 'search',
        text: '鉴定'
    }, {
        name: 'server-man',
        text: '售后'
    }, ])



    const handleScan = (type) => {
        if (token.value) {
            uni.navigateTo({
                url: `/pages/productInfo/productInfo?type=${type}`
            })
        } else {
            uni.showModal({
                title: '提示',
                content: '您还未登录，点击确认跳转登录页面',
                success: (res) => {
                    if (res.confirm) {
                        uni.reLaunch({
                            url: '/pages/login/login'
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消');
                    }
                }
            })
        }
    }

    const goToPage = (page) => {
        if (token.value) {
            uni.navigateTo({
                url: `/pages/${page}/${page}`
            })
        } else {
            uni.showModal({
                title: '提示',
                content: '您还未登录，点击确认跳转登录页面',
                success: (res) => {
                    if (res.confirm) {
                        uni.reLaunch({
                            url: '/pages/login/login'
                        })
                    } else if (res.cancel) {
                        console.log('用户点击取消');
                    }
                }
            })
        }
    }

    onLoad(() => {
        token.value = uni.getStorageSync('token')
    })
</script>

<style lang="scss" scoped>

</style>